package cn.juque.datapipeline.service.impl;

import cn.juque.datapipeline.entity.TaskGroupInfo;
import cn.juque.datapipeline.helper.QuartzHelper;
import cn.juque.datapipeline.mapper.TaskGroupInfoMapper;
import lombok.extern.slf4j.Slf4j;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author juque
 * @version 1.0.0
 * <ul>
 *     <li>TaskCheckGroupJobServiceImpl</li>
 * </ul>
 * @date 2023-04-09 00:08:08
 **/
@Slf4j
@Service("taskCheckGroupJobService")
public class TaskCheckGroupJobServiceImpl implements Job {

    @Resource
    private TaskGroupInfoMapper taskGroupInfoMapper;

    @Resource
    private QuartzHelper quartzHelper;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) {
        List<TaskGroupInfo> groupList = this.taskGroupInfoMapper.queryGroupInfoList(new TaskGroupInfo());
        groupList.stream()
                .filter(f -> Boolean.FALSE.equals(this.quartzHelper.existsJob(f.getId())))
                .forEach(f -> this.quartzHelper.addJob(f));
    }
}
